package com.deng.common.control
{
	import com.deng.permission.model.PermissionModelLocator;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.mxml.RemoteObject;
	
	public class LogController
	{
		private static var destination:String = "LogImpl";
		private static var lc:LogController;
		public function LogController()
		{
			
		}
		public static function getInstance():LogController
		{
			if(lc == null)
			{
				lc = new LogController();
			}
			return lc;
		}
		public function flt(flt:FaultEvent)
		{
			Alert.show(flt.fault.getStackTrace());
		}
		
		public function addLog(user_id:String,user_name:String,
			module:String,operation:String):void
		{
			var ro:RemoteObject = new RemoteObject();
			ro.destination = destination;
			ro.addEventListener(FaultEvent.FAULT,flt);
			ro.addEventListener(ResultEvent.RESULT,addLogRst);
			ro.addLog(user_id,user_name, module,operation);
		}
		public function addLogRst(rst:ResultEvent):void
		{
//			Alert.show("aa");
		}
		
		public function getAllLogRst(rst:ResultEvent):void
		{
//			Alert.show("aaa");
		}
		
		
		public function getLogByConditions(user_name:String,user_id:String,module:String,
					operation:String,fromTime:String,toTime:String,page:int,pos:int):void
		{
			var ro:RemoteObject = new RemoteObject();
			ro.destination = destination;
			ro.addEventListener(FaultEvent.FAULT,flt);
			ro.addEventListener(ResultEvent.RESULT,getLogByConditionsRst);
			ro.getLogByConditions(user_name,user_id,module,
					operation,fromTime,toTime,page,pos);
		}
		public function getLogByConditionsRst(rst:ResultEvent):void
		{						
			PermissionModelLocator.getInstance().page = (rst.result as ArrayCollection).getItemAt(0) as int;
			PermissionModelLocator.getInstance().totalPage = (rst.result as ArrayCollection).getItemAt(1) as int;
			PermissionModelLocator.getInstance().logArr = (rst.result as ArrayCollection).getItemAt(2) as ArrayCollection;
			
//			Alert.show(PermissionModelLocator.getInstance().logArr.length+"  ");
		}
	}
}